﻿// =================================================================== 
// 模块说明
//====================================================================
// 创建时间：2018-06-08 16:43:20
// 负责人：Sushee
// ===================================================================
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq.Expressions;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using OF.Utility;
using OF.Component.Model;
using OF.Component.IDAL;
using System.Text;
using OF.Component.DTO;

namespace OF.Component.DAL
{
	
	/// <summary>
	///评论信息 数据访问层
	/// </summary>	
	internal partial class Comment
	{		
    
        /// <summary>
    	/// 根据断言条件获取单个评论信息
    	/// </summary>
        public CommentInfo QuerySingle(Expression<Func<CommentInfo, bool>> predicate)
	    {
            return SQLServerProvider.CreateObject(ConnectionStringKey, predicate);
        }
        /// <summary>
    	/// 根据断言条件获获取评论信息列表
    	/// </summary>
	    public IList<CommentInfo> QueryList(Expression<Func<CommentInfo, bool>> predicate)
	    {
	        return SQLServerProvider.CreateList(ConnectionStringKey, predicate);
	    }

        /// <summary>
        /// 获取评论用户信息
        /// </summary>
        /// <param name="postId"></param>
        /// <param name="dataType"></param>
        /// <returns></returns>
        public List<PostDetailCommentDto> GetPostCommentShopInfoByPostIdAndDataType(int postId, int dataType)
        {
            List<PostDetailCommentDto> list = new List<PostDetailCommentDto>();
            string sql = @"SELECT b.ShopID,b.UserName,b.ShopName,a.Content from Comment a
		                    INNER JOIN Shop b
		                    ON a.CommentUserID=b.shopid where a.ContentID=@PostId and a.commenttype=@dataType";
            Database db = DatabaseFactory.CreateDatabase(this.ConnectionStringKey);
            DbCommand dbc = db.GetSqlStringCommand(sql);

            db.AddInParameter(dbc, "@PostId", DbType.Int32, postId);
            db.AddInParameter(dbc, "@dataType", DbType.Int32, dataType);
            using (IDataReader dr = db.ExecuteReader(dbc))
            {
                while (dr.Read())
                {
                    //string[] arr = new string[] { string.Format("{0}({1})", dr["UserName"].ToString(), dr["ShopName"].ToString()), dr["Content"].ToString() };
                    //list.Add(arr);
                    var info = SQLServerProvider.Create<PostDetailCommentDto>(dr);
                    list.Add(info);
                }
            }
            return list;
        }

    }
	
}